addModule({

	name : "Flow Chart",
	
	//数据默认值
	config : {
		nodes: [],
		links: [],
		category: {
			color: {
				0: 'red'
			}
		},

		duration: 20000,
	},

	graphic : {
		opt : null,
	},

	init : function() {
        addSceneFunc("Flow-chart-scene1", this.scene1, this.name, null);
	},

	handleData : function() {
		//回调函数，使文本超过6个就换行
		var labelFormatter = function(obj) {
			var name = obj.name;
			var strs = name.split(''); //字符串数组
			var str = ''
			for (var i = 0, s; s = strs[i++];) { //遍历字符串数组
				str += s;
				if (!(i % 6))
					str += '\n'; //按需要求余
			}
			return str;
		}

		// category
		var categories = this.config.category;
		if (categories == null) {
			categories = {};
		}
		if (categories.color == null) {
			categories.color = ['red'];
		}
		if (categories.color[0] == null) {
			categories.color[0] = 'red';
		}
		if (categories.symbol == null) {
			categories.symbol = ['circle'];
		}
		if (categories.symbol[0] == null) {
			categories.symbol[0] = 'circle';
		}
		if (categories.symbolSize == null) {
			categories.symbolSize = ['100'];
		}
		if (categories.symbolSize[0] == null) {
			categories.symbolSize[0] = '100';
		}
		if (categories.symbolRotate == null) {
			categories.symbolRotate = ['0'];
		}
		if (categories.symbolRotate[0] == null) {
			categories.symbolRotate[0] = '0';
		}
		if (categories.symbolOffest == null) {
			categories.symbolOffest = ['[0,0]'];
		}
		if (categories.symbolOffest[0] == null) {
			categories.symbolOffest[0] = '[0,0]';
		}

		// nodes
		var nodes = this.config.nodes;
		var len = nodes.length;
		var nodeData = [];

		for(var i=0; i<len; i++){
			var node = nodes[i];
			var category = node.category;

			if (category == null) {
				category = 0;
			}

			var color = categories.color[category];
			if (color == null) {
				color = categories.color[0];
			}

			var symbol = categories.symbol[category];
			if (symbol == null) {
				symbol = categories.symbol[0];
			}

			var symbolSize = categories.symbolSize[category];
			if (symbolSize == null) {
				symbolSize = categories.symbolSize[0];
			}

			var symbolRotate = categories.symbolRotate[category];
			if (symbolRotate == null) {
				symbolRotate = categories.symbolRotate[0];
			}

			var symbolOffest = categories.symbolOffest[category];
			if (symbolOffest == null) {
				symbolOffest = categories.symbolOffest[0];
			}


			nodeData.push({
				name : node.name,
				value : node.pos,
				symbol:symbol,
				symbolSize:symbolSize,
				symbolRotate:symbolRotate,
				symbolOffest:symbolOffest,
				label:{formatter : labelFormatter},
				itemStyle: {
					color: color
				}
			});
		}

		// links
		var links = this.config.links;
		len = links.length;

		var linkData = [];
		for(var i=0; i<len; i++){
			linkData.push({
				source : links[i].src,
				target : links[i].dest,
			});
		}

		return {
			nodes: nodeData,
			links: linkData,
			category: categories
		};
	},

	scene1 : function() {

		var data = this.handleData();

		var option = {
			tooltip : {},
			xAxis : {
				show : false,
				type : 'value',
				//boundaryGap : false,
				min : 0,
				max : 100,
			},
			yAxis : {
				show : false,
				min : 0,
				max : 100,
				type : 'value'
			},
			grid : {
				top : 0,
				right : 0,
				left : 0,
				bottom : 0
			},
			series : [ {
				// animationDurationUpdate: 1500,
				//animationEasing: 'quinticInOut',
				animationDuration : 3000,
				animationEasing : 'fadeIn',
				type : 'graph',
				layout : 'none',
				coordinateSystem : 'cartesian2d',
				//symbolSize : 100,
				animationDelay : function(idx) {
					return idx * 1000;
				},
				itemStyle : {
					shadowColor : 'rgba(0, 0, 0, 0.5)',
					shadowBlur : 15,
					shadowOffsetX : 5,
					shadowOffsetY : 5
				},
				label : {
					normal : {
						show : true,
						//fontFamily: 'Microsoft YaHei', 
						fontWeight : 'bolder',
						//lineHight:56,             
						fontSize : 12.5
					}
				},
				edgeSymbol : [ 'circle', 'arrow' ],
				edgeSymbolSize : [ 5, 12 ],
				edgeLabel : {
					normal : {
						textStyle : {
							fontSize : 20
						}
					}
				},
				data : data.nodes,

				links: data.links,
				
				lineStyle : {
					normal : {
						opacity : 0.9,
						width : 4,
						curveness : 0.2
					}
				}
			}]
		};
		this.graphic.opt = option;
		myChart.setOption(option);

		addRenderFunc("flow-chart", function() {
			myChart.clear();
			endScene();
		}, {
			once : true,
			delay : this.config.duration,
		});
    },
    
});
